# Flags

LIBRETRO_COMMON_FLAGS ?= "-D__LIBRETRO__ -fPIC -shared"
LIBRETRO_OPTIMIZATION_FLAGS ?= "-O3 -pipe" 

FULL_OPTIMIZATION = "${LIBRETRO_OPTIMIZATION_FLAGS}"

LIBRETRO_EXTRA_CXXFLAGS ?= ""
LIBRETRO_EXTRA_CFLAGS ?= ""
LIBRETRO_EXTRA_ASFLAGS ?= ""

CORE_COUNT ?= "${@oe.utils.cpu_count()}"

LIBRETRO_LTO_ENABLED ?= "0"
LIBRETRO_LTO_FLAGS ?= "${@bb.utils.contains('LIBRETRO_LTO_ENABLED', '1', '-flto=${CORE_COUNT}', '', d)}"

LIBRETRO_MAKEFILE_ASFLAGS ?= "ASFLAGS=${LIBRETRO_EXTRA_ASFLAGS}"
LIBRETRO_MAKEFILE_CXXFLAGS ?= "CXXFLAGS=${TARGET_CXXFLAGS}"
LIBRETRO_MAKEFILE_CFLAGS ?= "CFLAGS=${TARGET_CFLAGS}"

# https://gcc.gnu.org/gcc-10/porting_to.html
# fallback to fcommon for now
TARGET_CFLAGS += "-fcommon"

# Add additional CFLAGS
TARGET_CFLAGS += "${LIBRETRO_COMMON_FLAGS}" 
TARGET_CFLAGS += "${LIBRETRO_EXTRA_CFLAGS}"
TARGET_CFLAGS += "${LIBRETRO_LTO_FLAGS}"

# Add additional CXXFLAGS (TARGET_CXXFLAGS contains TARGET_CFLAGS)
TARGET_CXXFLAGS += "${LIBRETRO_EXTRA_CXXFLAGS}"

# Pass CXXFLAGS to linker when LTO'ing
TARGET_LDFLAGS += "${@bb.utils.contains('LIBRETRO_LTO_ENABLED', '1', '${TARGET_CXXFLAGS}', '', d)}"